package top.forforever.srb.core.controller.admin;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.forforever.srb.common.result.R;
import top.forforever.srb.core.pojo.entity.BorrowInfo;
import top.forforever.srb.core.pojo.vo.BorrowInfoApprovalVO;
import top.forforever.srb.core.pojo.vo.BorrowInfoVO;
import top.forforever.srb.core.pojo.vo.BorrowerApprovalVO;
import top.forforever.srb.core.service.BorrowInfoService;
import top.forforever.srb.core.util.AuthContextHolder;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 借款信息表 前端控制器
 * </p>
 *
 * @author Mr.Jiang
 * @since 2023-04-29
 */
@RestController
@RequestMapping("/admin/core/borrowInfo")
public class AdminBorrowInfoController {

    @Autowired
    private BorrowInfoService borrowInfoService;

    @GetMapping("getPageInfo/{pageNum}/{pageSize}")
    public R getPageInfo(@PathVariable Integer pageNum,
                         @PathVariable Integer pageSize) {
        List<BorrowInfoVO> list = borrowInfoService.getPageInfo(pageNum,pageSize);
        return R.ok().data("list",list);
    }

    @GetMapping("getBorrowInfoById/{id}")
    public R getBorrowInfoById(@PathVariable Long id) {
        BorrowInfo borrowInfo = borrowInfoService.getById(id);
        return R.ok().data("borrowInfo",borrowInfo);
    }

    @PostMapping("saveBorrowInfo")
    public R approvalSubmit(@RequestBody BorrowInfoApprovalVO borrowInfoApprovalVO) {
        borrowInfoService.approvalSubmit(borrowInfoApprovalVO);
        return R.ok();
    }

    @GetMapping("show/{borrowInfoId}")
    public R show(@PathVariable Long borrowInfoId) {
        Map<String,Object> borrowInfoDetail = borrowInfoService.getBorrowInfoDetail(borrowInfoId);
        return R.ok().data("borrowInfoDetail",borrowInfoDetail);
    }

}

